home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / getCameraNode.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.6 KB  |  130 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  16 June 1997
  22. //  Author:         cdt
  23. //
  24. //  Procedure Name:
  25. //      getCameraNode
  26. //
  27. //  Description:
  28. //      Procedure to get the name of a camera node.
  29. //
  30. //  Input Arguments:
  31. //      node - name of node to get
  32. //      camera - camera name to get nodes for
  33. //
  34. //  Return Value:
  35. //      Name of the requested camera node
  36. //
  37.  
  38. //
  39. //  Procedure Name:
  40. //      getLookAtNode
  41. //
  42. proc string getLookAtNode( string $camera )
  43. {
  44.     string $lookAts[] = `listConnections ($camera+".rotateX")`;
  45.  
  46.     if (size($lookAts) == 0 || `objectType $lookAts[0]` != "lookAt")
  47.         $lookAts = `listConnections ($camera+".rotateY")`;
  48.  
  49.     if (size($lookAts) == 0 || `objectType $lookAts[0]` != "lookAt")
  50.         $lookAts = `listConnections ($camera+".rotateZ")`;
  51.  
  52.     return (size($lookAts) == 0 || `objectType $lookAts[0]` != "lookAt") ?
  53.         "" : $lookAts[0];
  54. }
  55.  
  56. //
  57. //  Procedure Name:
  58. //      getViewNode
  59. //
  60. proc string getViewNode( string $camera )
  61. {
  62.     string $views[];
  63.  
  64.     string $lookAt = getLookAtNode( $camera );
  65.  
  66.     if ($lookAt != "") {
  67.         $views = `listConnections ($lookAt+".target[0].targetTranslateX")`;
  68.  
  69.         if (size($views) == 0 || `objectType $views[0]` != "transform")
  70.             $views = `listConnections ($lookAt+".target[0].targetTranslateY")`;
  71.  
  72.         if (size($views) == 0 || `objectType $views[0]` != "transform")
  73.             $views = `listConnections ($lookAt+".target[0].targetTranslateZ")`;
  74.     }
  75.  
  76.     return (size($views) != 0 && `objectType $views[0]` == "transform") ?
  77.         $views[0] : "";
  78. }
  79.  
  80. //
  81. //  Procedure Name:
  82. //      getUpNode
  83. //
  84. proc string getUpNode( string $camera )
  85. {
  86.     string $ups[];
  87.  
  88.     string $lookAt = getLookAtNode( $camera );
  89.  
  90.     if ($lookAt != "")
  91.         $ups = `listConnections ($lookAt+".worldUpMatrix")`;
  92.  
  93.     return (size($ups) > 0) ? $ups[0] : "";
  94. }
  95.  
  96. //
  97. //  Procedure Name:
  98. //      cameraNode
  99. //
  100. global proc string getCameraNode( string $node, string $camera )
  101. {
  102.     string $result = "";
  103.  
  104.     if ( "camera" == `nodeType $camera` ) {
  105.         // In cases where there are more than one shape under a transform and
  106.         // one of them is a camera, it is possible that this method will be
  107.         // called with the actual camera node instead of the transform above
  108.         // it.  Compensate.
  109.         //
  110.         string $parents[] = `listRelatives -parent $camera`;
  111.         $camera = $parents[0];
  112.     }
  113.  
  114.     switch ($node) {
  115.     case "lookAt":
  116.         $result = getLookAtNode( $camera );
  117.         break;
  118.  
  119.     case "view":
  120.         $result = getViewNode( $camera );
  121.         break;
  122.  
  123.     case "up":
  124.         $result = getUpNode( $camera );
  125.         break;
  126.     }
  127.  
  128.     return $result;
  129. }
  130.